package org.zhaolei.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zhaolei.interceptor.LoginInterceptor;

/**
 * 拦截器配置文件，把之前创建的登录拦截器加入
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

//    public LoginInterceptor loginInterceptor() {
//        return new LoginInterceptor();
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //这里也可以直接new一个LoginInterceptor对象，然后传进去！！！
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/api/user/*/**", "/api/address/*/**")
                //排查不拦截的路径
                .excludePathPatterns("/api/user/*/send_code", "/api/user/*/captcha",
                        "/api/user/*/register", "/api/user/*/login", "/api/user/*/upload");
    }

}
